//
//  ZXZGowuViewController.m
//  zuxianzhi
//
//  Created by tyu on 27.5.24.
//

#import "ZXZGowuViewController.h"
#import "ZXZGowuView.h"
#import "ZXZHomeGoodsViewController.h"
#import "ZXZNoDataView.h"

@interface ZXZGowuViewController ()

@property(nonatomic,weak) UIScrollView *ScrollView;
@property(nonatomic,weak) ZXZGowuView *goodsView1;
@property(nonatomic,weak) ZXZGowuView *goodsView2;
@property(nonatomic,weak) ZXZGowuView *goodsView3;
@property(nonatomic,weak) ZXZNoDataView *dataView;
@property(nonatomic,assign) int indexType;

@end

@implementation ZXZGowuViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self checkIsLogin:^{
        [self updata];
    }];
}



- (void)updata
{
    int type = [[userDef valueForKey:@"gouwutype"] intValue];
    self.indexType = type;
  
    self.dataView.hidden = YES;
    self.goodsView1.hidden = NO;
    
    self.goodsView1.TitleLab.text = [userDef valueForKey:@"gouwuTile"];
    self.goodsView1.ImgV.image = [UIImage imageNamed:[userDef valueForKey:@"gouwuImage"]];
    
    if (type==1) {
    
    }else if (type == 2){
        
          
    }else if (type == 3){
        
    }else{
        self.dataView.hidden = NO;
        self.goodsView1.hidden = YES;
    }
    
}



- (void)checkIsLogin:(void(^)(void))complete
{
    if ([[userDef valueForKey:islogin] intValue] != 1) {
        self.dataView.hidden = NO;
        self.goodsView1.hidden = YES;

    }else{
        if (complete){
            complete();
        }
    }

}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
}

- (void)bac_addUI
{
    [super bac_addUI];
    [self setupView];
    self.bacbBackBtn.hidden = YES;

    UIImageView *topImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"home_topImageV"]];
    [self.view addSubview:topImageV];
    topImageV.userInteractionEnabled = YES;
    topImageV.frame = CGRectMake(0, 0, ScreenWidth, ScreenWidth * 244 / 750);
    
    self.navView.backgroundColor = UIColor.clearColor;
    [self.view bringSubviewToFront:self.navView];
    UILabel *titleLeftLab = [[UILabel alloc]init];
    [self.navView addSubview:titleLeftLab];
    titleLeftLab.text = [NSString stringWithFormat:@"购物车"];
    titleLeftLab.textColor = [UIColor blackColor];
    titleLeftLab.font = [UIFont systemFontOfSize:25 weight:UIFontWeightMedium];
    titleLeftLab.frame =CGRectMake(20, 50, 120, 40);

    ZXZNoDataView *dataView = [ZXZNoDataView new];
    [self.ScrollView addSubview:dataView];
    self.dataView = dataView;
    dataView.TitleLab.text  = @"暂无数据";
    dataView.frame = CGRectMake(0, 250, ScreenWidth, 150);
    
    [self updata];
}

- (void)setupView{
    UIScrollView *ScrollV = [[UIScrollView alloc]init];
    [self.view addSubview:ScrollV];
    self.ScrollView =ScrollV;

    ScrollV.contentSize = CGSizeMake(ScreenWidth, ScreenHeight*1.5);
    ScrollV.contentInset = UIEdgeInsetsMake(0, 0, -10, 0);
    ScrollV.showsVerticalScrollIndicator = NO;
    ScrollV.frame = CGRectMake(0, 100, ScreenWidth, ScreenHeight-ShowDiff);

    
    ZXZGowuView *goods = [[ZXZGowuView alloc]init];
    [self.ScrollView addSubview:goods];
    goods.backgroundColor = [UIView ColorWithHexString:@"#F2F4F9"];

    goods.ImgV.image = [UIImage imageNamed:@"goods1"];
    goods.TitleLab.text = @"Insta360 x4";
    goods.SubLab.text = @"押金 ￥800     租金 ";
    goods.zujinLab.text = @"￥150/天";

    self.goodsView1 = goods;
    goods.ClcikBlock = ^(NSString * _Nonnull Str) {
        [self pushIndex];
    };
    
    CGFloat height = 140;
    CGFloat width = (ScreenWidth-30);

    self.goodsView1.frame = CGRectMake(10, 10, width, height);
    self.goodsView1.layer.cornerRadius = 5;
    self.goodsView1.layer.masksToBounds = YES;
}


- (void)pushIndex
{
    ZXZHomeGoodsViewController *vc = [ZXZHomeGoodsViewController new];
    vc.index = self.indexType;
    [self.navigationController pushViewController:vc animated:YES];
}


@end
